package leetcode;

/**
 * Created by Ghost on 2014/11/22.
 */
public class Minimum_Depth_of_Binary_Tree {
    int min = 0;

    private void depth(TreeNode root, int curDepth) {
        if(root!=null){
            if (root.left == null && root.right==null) {
                if (min == 0)
                    min = curDepth;
                else
                    min = curDepth < min ? curDepth : min;
            } else {
                depth(root.left,curDepth+1);
                depth(root.right,curDepth+1);
            }
        }
    }

    public int minDepth(TreeNode root) {
        depth(root,1);
        return min;
    }
    public static void main(String[] args){
        Minimum_Depth_of_Binary_Tree minimum_depth_of_binary_tree = new Minimum_Depth_of_Binary_Tree();
        TreeNode root = new TreeNode(1);
//        root.left = new TreeNode(2);
//        root.right = new TreeNode(54);
//        root.left.left = new TreeNode(3);
        System.out.println(minimum_depth_of_binary_tree.minDepth(null));
    }

}
